package com.coocaa.optimizer.movie.cleaner;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;

import com.coocaa.optimizer.OptimizerApplication;
import com.coocaa.optimizer.R;
import com.coocaa.optimizer.movie.cleaner.manager.CleanerManager;
import com.coocaa.optimizer.movie.cleaner.manager.CleanerManagerFactory;

public class MovieCleanerMainActivity extends Activity {
    private CleanerManager cleanerManager = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        cleanerManager = CleanerManagerFactory.factory.create(this);

        initCleanNowButton();
        initAutoCleanCheckbox();
        initFixMovieplatformButton();
    }

    private void initCleanNowButton() {
        Button btnCleanNow = (Button) findViewById(R.id.button_clean_now);
        btnCleanNow.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cleanerManager.cleanNow();
                OptimizerApplication.toast(MovieCleanerMainActivity.this, getResources().getString(R.string.clean_now_success));
            }
        });
    }

    private void initAutoCleanCheckbox() {
        CheckBox cbAutoClean = (CheckBox) findViewById(R.id.checkbox_auto_clean);
        cbAutoClean.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                cleanerManager.setAutoClean(isChecked);
            }
        });
        cbAutoClean.setChecked(cleanerManager.canAutoClean());
    }

    private void initFixMovieplatformButton() {
        Button btn = (Button) findViewById(R.id.button_fix_movieplatform);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                cleanerManager.fixMoviepltform();
                OptimizerApplication.toast(MovieCleanerMainActivity.this, getResources().getString(R.string.fix_movieplatform_success));
            }
        });
    }
}
